var port = require('../../modules/port.js');


//获取应用实例
var app = getApp()
Page({
    data: {
        indexData: [],
        dataList: [],
        classHover: 0,
        scrollLeft: 0
    },
    onLoad: function () {
        var that = this;
        wx.request({
            url: port.dataPort.indexInfo,
            method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT    
            // header: {}, // 设置请求的 header    
            success: function (data) {
                that.setData({
                    indexData: data.data.data
                })
            }
        })
        that.requestData(0);
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.hideNavigationBarLoading();
    },
    requestData: function (id) {
        wx.showNavigationBarLoading();
        var that = this;
        var recommendData = '';
        var hotData = '';
        var adData = '';
        wx.request({
            url: port.dataPort.indexList,
            data: { classId: id },
            method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT    
            // header: {}, // 设置请求的 header    
            success: function (data) {
                that.setData({
                    dataList: data.data.data
                })
                wx.hideNavigationBarLoading();
            }
        })
    },
    // 作品请求链接
    articleRequest: function (e) {
        wx.navigateTo({
            url: '../article/article?id=' + e.currentTarget.dataset.id
        })
    },
    // 内容请求链接
    contentRequest: function (e) {
        wx.navigateTo({
            url: '../content/content?id=' + e.currentTarget.dataset.id
        })
    },
    classRequest: function (e) {
        this.requestData(e.currentTarget.dataset.id);
        this.setData({
            classHover: e.currentTarget.dataset.id
        })
        if (e.currentTarget.dataset.index == 4 ) {
            this.setData({
                scrollLeft: 300
            })
        }
    },
    searchBtn: function () {
        wx.navigateTo({
            url: '../search/search'
        })
    },
    imgLoad: function (e) {
        console.log(e.detail);
    }
})
